package com.xydtech.ecard.statistics.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.statistics.domain.EcardUserChecking;
import com.xydtech.ecard.statistics.domain.EcardUserCheckingSum;
import com.xydtech.ecard.statistics.service.IEcardUserCheckingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户考勤Controller
 *
 * @author JHON
 * @date 2022-07-22
 */
@Controller
@RequestMapping("/statistics/userChecking")
public class EcardUserCheckingController extends BaseController {
    private String prefix = "statistics/userChecking";

    @Autowired
    private IEcardUserCheckingService ecardUserCheckingService;


    @GetMapping("/{deptId}")
    public String userChecking(@PathVariable("deptId") Long deptId, ModelMap mmap) {
        mmap.put("deptId", deptId);
        return prefix + "/userChecking";
    }

    @GetMapping("userCheckingList/{userId}")
    public String userCheckingList(@PathVariable("userId") Long userId, ModelMap mmap) {
        mmap.put("userId", userId);
        return prefix + "/userCheckingList";
    }

    /**
     * 查询用户考勤列表
     */
    @RequiresPermissions("statistics:userChecking:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardUserChecking ecardUserChecking) {
        if (ecardUserChecking.getDeptId() == null) {
            ecardUserChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        startPage();
        List<EcardUserChecking> list = ecardUserCheckingService.selectEcardUserCheckingList(ecardUserChecking);
        return getDataTable(list);
    }

    /**
     * 查询用户考勤汇总
     */
    @RequiresPermissions("statistics:userChecking:list")
    @PostMapping("/sumList")
    @ResponseBody
    public TableDataInfo sumList(EcardUserChecking ecardUserChecking) {
        if (ecardUserChecking.getDeptId() == null) {
            ecardUserChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        List<EcardUserCheckingSum> list = ecardUserCheckingService.selectEcardUserCheckingSum(ecardUserChecking);
        return getDataTable(list);
    }

    /**
     * 导出用户考勤汇总
     */
    @RequiresPermissions("statistics:userChecking:export")
    @Log(title = "用户考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSum")
    @ResponseBody
    public AjaxResult exportSum(EcardUserChecking ecardUserChecking) {
        if (ecardUserChecking.getDeptId() == null) {
            ecardUserChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        List<EcardUserCheckingSum> list = ecardUserCheckingService.selectEcardUserCheckingSum(ecardUserChecking);
        ExcelUtil<EcardUserCheckingSum> util = new ExcelUtil<EcardUserCheckingSum>(EcardUserCheckingSum.class);
        return util.exportExcel(list, "用户考勤数据");
    }

    /**
     * 导出用户考勤列表
     */
    @RequiresPermissions("statistics:userChecking:export")
    @Log(title = "用户考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardUserChecking ecardUserChecking) {
        if (ecardUserChecking.getDeptId() == null) {
            ecardUserChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        List<EcardUserChecking> list = ecardUserCheckingService.selectEcardUserCheckingList(ecardUserChecking);
        ExcelUtil<EcardUserChecking> util = new ExcelUtil<EcardUserChecking>(EcardUserChecking.class);
        return util.exportExcel(list, "用户考勤数据");
    }

}
